package com.example.my.agiftthat.ui.list;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.my.agiftthat.R;
import com.example.my.agiftthat.helper.RecyclerViewAdapterHelper;
import com.example.my.agiftthat.ui.list.intentlist.ListIntentActivity;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by My on 2016/12/21.
 */

public class FragmentAdapter extends RecyclerViewAdapterHelper<UserBean.DataBean.ItemsBean> {

    public FragmentAdapter(Context context, List<UserBean.DataBean.ItemsBean> list) {
        super(context, list);
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.fragment_comment_item, parent, false);
        return new ViewHolder(view);
    }



    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, final int position) {
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ListIntentActivity.class);
                Bundle bundle = new Bundle();
                bundle.putInt("id",list.get(position).getId());
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });
        if(holder instanceof  ViewHolder){
            if(!(list.get(position).getShort_description() == null)) {
                ((ViewHolder) holder).text1CommentItem.setText(list.get(position).getShort_description());
            }else {
                ((ViewHolder) holder).text1CommentItem.setText("");
            }
            if(!(list.get(position).getName() == null)){
                ((ViewHolder) holder).text2CommentItem.setText(list.get(position).getName());
            }else {
                ((ViewHolder) holder).text2CommentItem.setText("");
            }

            ((ViewHolder) holder).text3CommentItem.setText("￥ "+list.get(position).getPrice());
            Glide.with(context).load(list.get(position).getCover_image_url()).into(((ViewHolder) holder).imageCommentItem);
        }
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.image_comment_item)
        ImageView imageCommentItem;
        @Bind(R.id.text1_comment_item)
        TextView text1CommentItem;
        @Bind(R.id.text2_comment_item)
        TextView text2CommentItem;
        @Bind(R.id.text3_comment_item)
        TextView text3CommentItem;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
